package com.itheima.exception;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

//切面
@Aspect
//被扫描
@Component
public class TrimAdvice {
    //定义切点
    @Pointcut("execution(* com.itheima.service.UserService.getUrl())")
    public void pc(){}
    //通知
    @Around("TrimAdvice.pc()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        //1.获取参数
        Object[] args = pjp.getArgs();
        //2.空格处理 业务
        for (int i = 0; i < args.length; i++) {
            String string = args[i].toString();
            String trim = string.trim();
            args[i]=trim;
        }
        //3.执行业务
        Object proceed = pjp.proceed();
        return proceed;
    }
}
